<?php
	require_once ROOT_PATH.DS.'includes'.DS.'template.class.php';
//	function __autoload($classname) {
//	   require_once("pages/" . $classname . ".php");
//	}
	$skn = new MiniTemplator("templates");
	function &skn()
	{
		global $skn;
		return $skn;
	}
	function in_debug(){
        if (! IN_DEBUG)
			return;		
		ob_start ();
        echo '<style type="text/css">#system-debug{font-size: 9pt; margin-top:10px;color:#555555; line-height: 1.5em;} 
				#system-debug div#sql-report strong{ color:#F00}
			</style><div id="system-debug" class="profiler"><h3>IN DEBUG ENVIROMENT</h3>';
    	$newlineSQLKeywords = '/<strong>' . '(FROM|LEFT|INNER|OUTER|WHERE|SET|VALUES|ORDER|GROUP|HAVING|LIMIT|ON|AND|OR)' . '<\\/strong>/i';
    	$sqlKeyword = array ('ASC', 'AS', 'ALTER', 'AND', 'AGAINST', 'BETWEEN', 'BOOLEAN', 'BY', 'COUNT', 'DESC', 'DISTINCT', 'DELETE', 'EXPLAIN', 'FOR', 'FROM', 'GROUP', 'HAVING', 'INSERT', 'INNER', 'INTO', 'IN', 'JOIN', 'LIKE', 'LIMIT', 'LEFT', 'MATCH', 'MODE', 'NOT', 'ORDER', 'OR', 'OUTER', 'ON', 'REPLACE', 'RIGHT', 'STRAIGHT_JOIN', 'SELECT', 'SET', 'TO', 'TRUNCATE', 'UPDATE', 'VALUES', 'WHERE' );
    	
    	$sqlReplaceKeyword = array ('<strong>ASC</strong>', '<strong>AS</strong>', '<strong>ALTER</strong>', '<strong>AND</strong>', '<strong>AGAINST</strong>', '<strong>BETWEEN</strong>', '<strong>BOOLEAN</strong>', '<strong>BY</strong>', '<strong>COUNT</strong>', '<strong>DESC</strong>', '<strong>DISTINCT</strong>', '<strong>DELETE</strong><br />', '<strong>EXPLAIN</strong>', '<strong>FOR</strong>', '<strong>FROM</strong>', '<strong>GROUP</strong>', '<strong>HAVING</strong>', '<strong>INSERT</strong>', '<strong>INNER</strong>', '<strong>INTO</strong>', '<strong>IN</strong>', '<strong>JOIN</strong>', '<strong>LIKE</strong>', '<strong>LIMIT</strong>', '<strong>LEFT</strong>', '<strong>MATCH</strong>', '<strong>MODE</strong>', '<strong>NOT</strong>', '<strong>ORDER</strong>', '<strong>OR</strong>', '<strong>OUTER</strong>', '<strong>ON</strong>', '<strong>REPLACE</strong><br />', '<strong>RIGHT</strong>', '<strong>STRAIGHT_JOIN</strong>', '<strong>SELECT</strong><br />&nbsp;', '<strong>SET</strong>', '<strong>TO</strong>', '<strong>TRUNCATE</strong><br />', '<strong>UPDATE</strong><br />', '<strong>VALUES</strong>', '<strong>WHERE</strong>' );
    	
    	$queriesLogNo = 0;
    	$executeTime = 0;
    	echo '<div id="sql-report"><h4>Queries Logged</h4><ol>';
        $daObjs =  Debug::debugs();
        if($daObjs)
        {
        	foreach ( $daObjs as $daObj ) {
        	    $sql = str_replace ( $sqlKeyword, $sqlReplaceKeyword,$daObj);
        		$sql = preg_replace ( '/\"([^\"])+\"/', '<font color="#ff000;">\\0</font>', $sql );
        		$sql = preg_replace ( '/\'([^\'])+\'/', '<font color="#ff000;">\\0</font>', $sql );
        		$sql = preg_replace ( $newlineSQLKeywords, '<br />&nbsp;&nbsp;\\0', $sql );
        		echo '<li>' . $sql . '<br />&nbsp;&nbsp;&nbsp;&nbsp;</li>';
                $queriesLogNo++;
        	}
        }
    	echo '</ol><br />Total <strong>' . $queriesLogNo . '</strong> SQL queries logged take</h4><p></p>';
        $debug = ob_get_clean();
		return $debug;
    }  
?>